# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         get方法
# Description:
# Author:       asus
# Date:         2019/3/6
#-------------------------------------------------------------------------------


#dict与get方法相比get方法不会因为找不到而抛出异常

#找不到salary抛出异常
# dict = {"name":"Bill","age":30}
# value = dict["salary"]

#get方法
dict = {'a':20,'b':30,'c':40}
print(dict.get('x',0))#第二个参数是找不到时返回的参数


#例题
#定义一个英文字典
dict = {"help":"帮助","bike":"自行车","geek":"极客","China":"中国"}
while True:
    word = input("请输入英文单词：")
    if word == "exit":
        break;
    value = dict.get(word)
    if value == None:
        print("{}在字典里不存在。".format(word))
    else:
        print("{}的意思是{}。".format(word,value))